import os
import sys

sys.path.append(os.path.abspath(__file__).rsplit(os.sep, 1)[0])

import time
import unittest

from common import settings
from common.settings import SRC_DIR
from common.mailbox import Mail
from common.HTMLTestReport import HTMLTestRunner
from cases_example import personListTest, macManageTest


if __name__ == '__main__':
    if settings.DEBUG:
        suit = unittest.TestSuite()
        suit.addTests(unittest.makeSuite(macManageTest.MacManageTest))
        # suit.addTests(unittest.makeSuite(personListTest.PersonListTest))
        # suit.addTests(unittest.makeSuite(policeIncidentManageTest.PoliceIncidentManageTest))
    else:
        # suit = unittest.defaultTestLoader.discover(start_dir='./cases_example', pattern='*Test.py', top_level_dir=SRC_DIR)
        suit = unittest.TestSuite()
        suit.addTests(unittest.makeSuite(macManageTest.MacManageTest))
        suit.addTests(unittest.makeSuite(personListTest.PersonListTest))

    now = time.strftime('%Y-%m-%d_%H-%M-%S', time.localtime())
    with open(os.path.join(settings.REPORTS_DIR, "后台管理系统测试报告" + now + '.html'), 'wb') as fp:
        runner = HTMLTestRunner(stream=fp, verbosity=2, title='Test Report', description='')
        runner.run(suit)
    if not settings.DEBUG:
        name = 'bq@hzgosun.com'  # 自己邮箱
        issue = '277532844@qq.com'  # 发送多人用，分隔如：'pj.jiang@hzgosun.com, pj.jiang@hzgosun.com'
        accredit = 'dkJJU7JodbRciVHA'  # 授权码    详情配置咨询上方邮件那个小哥哥
        html = os.path.join(settings.REPORTS_DIR, "后台管理系统测试报告" + now + '.html')  # html文件名
        m = Mail(name, accredit, html, issue)
        m.mail_send()
